
const sass = require('sass')
module.exports = function (grunt) {

    grunt.initConfig({
        babel: {
            options: {
                sourceMap: true,
                presets: ['@babel/preset-env']
            },
            dist: {
                files: {
                    'dist/assets/scripts/main.js': 'src/assets/scripts/main.js'
                }
            }
        },
        sass: {
            options: {
                sourceMap: true,
                implementation: sass
            },
            main: {
                files: {
                    'dist/assets/styles/main.css': 'src/assets/styles/main.scss'
                }
            }
        },
        image: {
            dynamic: {
                files: [{
                    expand: true,
                    cwd: 'src/',
                    src: ['**/*.{png,jpg,gif,svg}'],
                    dest: 'dist/'
                }]
            }
        },
        copy: {
            main: {
                files: [
                    // includes files within path
                    { 
                        expand: true, 
                        cwd:'src/',
                        src: ['assets/fonts/*.eot', 'assets/fonts/*.ttf', 'assets/fonts/*.woff'], 
                        dest: 'dist/', 
                        filter: 'isFile' 
                    }
                ]
            },
        },
        html_template: {
            options: {
                locals:  {
                    pkg:{
                        name:'网站的标题'
                    },
                },
                beautify: {
                    indent_size: 2
                }
            },
            build_html: {
                options: {
                    force: true
                },
                expand: true,
                cwd: "src",
                src: "*.html",
                dest: "dist"
            }
        },
    });

    grunt.registerTask('compile', ['html_template','babel','sass','image','copy']);


    require('load-grunt-tasks')(grunt);
};